'use strict';
/////////////////////////////////////
// API集中服务
// =====================
// liuyp 2019年5月21日17:06:05
// liuyp 2020年5月19日17:39:01
/////////////////////////////////////
function $API($ajax, $timeout) {
    var $API = { List: {}, Add: {}, Edit: {}, Detail: {}, Drop: {} };
    $API.Drop.Customer = function(params){
        return new Promise(function(resolve, reject){
            $ajax.sent({
                method: 'GET',
                url: '/api/customer/getlistMock',
                params: params
            }).then(function(res) {
                resolve(res.data||[])
            }, reject);
        });
    };
    $API.Drop.BusiType = function(params){
        return new Promise(function(resolve, reject){
            $ajax.sent({
                method: 'GET',
                url: '/api/busi/typelist22',
                params: {
                    // 传参
                }
            }).then(function(res) {
                resolve(res.data||[])
            }, reject);
        });
    };
    $API.Drop.ArchiveStatus = function(params){
        var arr2 = [
            {"id": 0,"name":"未归档" },
            {"id": 1,"name":"已归档" }
        ];
        return new Promise(function(resolve, reject){
            resolve(arr2)
        });
    };
    $API.Drop.IncomeStatus = function(params){
        var arr2 = [
            {"id": 0,"name":"预估" },
            {"id": 1,"name":"暂定" },
            {"id": 2,"name":"封账" }
        ];
        return new Promise(function(resolve, reject){
            resolve(arr2)
        });
    };
    $API.Drop.SplitStatus = function(params){
        var arr2 = [
            {"id": 0,"name":"初始状态" },
            {"id": 1,"name":"成功" },
            {"id": -1,"name":"失败" }
        ];
        return new Promise(function(resolve, reject){
            resolve(arr2)
        });
    };
    ////////////////////////////////////////////////////
    $API.List.IncomeB2TB = function(params) {
        return new Promise(function(resolve, reject) {
            // 处理默认值 同时进行弥补处理
            params.beginx = params.begin;
            params.endx = params.end;
            params.keyWordx = params.keyWord;
            params.usernamex = params.username;
            $ajax.sent({
                method:'GET',
                url:'/api/Allot/IncomeB2TBList',
                params:params
            }).then(function(res) {
                resolve(res.data)
            }, reject);
        });
    }




    $API.Detail.cardfrom = function(opt) {
        return new Promise(function(resolve, reject){
            $ajax.sent({
                method: 'GET',
                url: 'cardfromDetail',
                params: opt // 传参
            }).then(function(res){
                resolve(res.data)
            });
        });
    };
    $API.Drop.lotteryList = function(opt) {
        return new Promise(function(resolve, reject){
            var nosearch = opt.indexOf('nosearch') > -1
            var noall = opt.indexOf('noall') > -1
            var arr = noall ? [{id: 0, name:'全部lotteryType'}] :[];
            $ajax.sent({
                method: 'GET',
                url: 'lotteryListApi',
                params: {
                    // 传参
                }
            }).then(function(res){
                resolve(select2Config( arr.concat(res.data||[]), 0 ))
            }, reject);
        });
    };
    $API.Drop.lotteryList2 = function(opt) {
        return new Promise(function(resolve, reject){
            var nosearch = opt.indexOf('nosearch') > -1
            var noall = opt.indexOf('noall') > -1
            var arr = noall ? [{id: 0, name:'全部lotteryType2'}] :[];
            var arr2 = [
                {'id': 0,'name':'啦啦' },
                {'id': 1,'name':'嘎嘎' },
                {'id': 2,'name':'嗯嗯' }
            ];
            resolve(select2Config( arr.concat(arr2), 0 ))
        });
    };
    ////////////////////////////////////////////////////
    $API.Drop.Manager = function(opt, params){
        var nosearch = opt.indexOf('nosearch') > -1
        var noall = opt.indexOf('noall') > -1
        var arr = noall ? [{id: 0, name:"全部用户"}] :[];
        return new Promise(function(resolve, reject){
            $ajax.sent({
                method:'GET',
                url:'/api/customer/GetManager',
                params:params
            }).then(function(res){
                resolve(select2Config( arr.concat(res.data.list), !nosearch ))
            }, reject);
        });
    };
    ////////////////////////////////////////////////////
    $API.Drop.customer = $API.Drop.Customer
    $API.Drop.busiType = $API.Drop.BusiType
    $API.Drop.archiveStatus = $API.Drop.ArchiveStatus
    $API.Drop.incomeStatus = $API.Drop.IncomeStatus
    $API.Drop.splitStatus = $API.Drop.SplitStatus
    ////////////////////////////////////////////
    //监听 cnzz 读 写
    $API.Detail.monitorCnzzDetail = function(opt) {
        return new Promise(function(resolve, reject){
            $ajax.sent({
                method: 'GET',
                url: '/api/monitor/cnzz_detail',
                params: opt // 传参
            }).then(function(res){
                resolve(res.data)
            }, reject);
        });
    };
    $API.Edit.monitorCnzzEdit = function(opt) {
        return new Promise(function(resolve, reject){
            $ajax.sent({
                method: 'POST',
                url: '/api/monitor/cnzz_edit',
                params: opt // 传参
            }).then(function(res){
                resolve(res.data)
            }, reject);
        });
    };
    // 用户 下拉框
    $API.Drop.customerGetList = function(opt, param) {
        return new Promise(function(resolve, reject){
            var nosearch = opt.indexOf('nosearch') > -1;
            var noall = opt.indexOf('noall') > -1
            var arr = noall ? [{id: 0, name:'全部${ title }'}] :[];
            $ajax.sent({
                method: 'GET',
                url: '/api/customer/getlist',
                params: param // 传参
            }).then(function(res){
                var arr2 = [];
                for(var i = 0, l = res.data.length; i < l; i++){
                    var one = res.data[i]
                    arr2.push({id: one.I, name: one.N})
                }
                resolve(select2Config( arr.concat(arr2), !nosearch ))
            }, reject);
        });
    };
    // 业务 下拉框
    $API.Drop.businessGetB2classBusi = function(opt, param) {
        return new Promise(function(resolve, reject){
            var nosearch = opt.indexOf('nosearch') > -1;
            var noall = opt.indexOf('noall') > -1
            var arr = noall ? [{id: 0, name:'全部${ title }'}] :[];
            $ajax.sent({
                method: 'GET',
                url: '/api/business/get_B2class_busi',
                params: param // 传参
            }).then(function(res){
                var arr2 = res.data;
                resolve(select2Config( arr.concat(arr2), !nosearch ));
            }, reject);
        });
    };
    // 监控 根据用户、业务获取推广-下拉框
    $API.Drop.monitorCnzzBizAdid = function(opt, param) {
        return new Promise(function(resolve, reject){
            var nosearch = opt.indexOf('nosearch') > -1;
            var noall = opt.indexOf('noall') > -1
            var arr = noall ? [{id: 0, name:'全部${ title }'}] :[];
            $ajax.sent({
                method: 'GET',
                url: '/api/monitor/cnzz_biz_adid',
                params: param // 传参
            }).then(function(res){
                var arr2 = res.data;
                resolve(select2Config( arr.concat(arr2), !nosearch ));
            }, reject);
        });
    };
    return $API
}
exports = module.exports = $API;